package com.heima.media.controller;

import com.heima.common.dto.PageResponseResult;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/v1/channel")
@Api(tags = "频道管理API")
public class ChannelController {

    @Autowired
    IChannelService channelService;


    /**
     *
     * @param channelDto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "根据名称模糊查询分页列表",notes = "author:mcm")
    @ApiImplicitParam(name="channelDto",value = "查询对象",required = true,dataType = "ChannelDto")
    public PageResponseResult listByName(@RequestBody ChannelDto channelDto){
        return  channelService.listByName(channelDto);
    }

    @PostMapping
    @ApiOperation(value = "新增频道",notes = "author:mcm")
    @ApiImplicitParam(name="wmChannel",value = "频道对象",required = true,dataType = "WmChannel")
    public ResponseResult saveWmChannel(@RequestBody WmChannel wmChannel){
        return  channelService.saveWmChannel(wmChannel);
    }
    /**
     * 修改频道
     */
    @PutMapping
    public ResponseResult updateWmChannel(@RequestBody WmChannel channel){
       channelService.updateById(channel);
       return ResponseResult.okResult();
    }
    /**
     * 删除频道
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
        return channelService.deleteById(id);

    }
    /**
     * 查询所有频道
     */
    @GetMapping("/channels")
    public ResponseResult channels(){
        List<WmChannel> channels = channelService.list();
        return ResponseResult.okResult(channels);
    }

}
